package com.algorithmic.sort;

import java.util.List;

/**
 * @author: zhangxupeng
 * @date:2019/6/25
 * @Email: 1452806452@qq.com
 * 冒泡排序算法
 **/
public class BubbleSort {
    /**
     * 冒泡排序算法
     * 时间复杂度O(N^2)
     *
     * @param list 待排序的list
     */
    public static void bubbleSort(List<Integer> list) {
        for (int out = list.size() - 1; out > 0; out--) {
            for (int in = 0; in < out; in++) {
                if (list.get(in) > list.get(in + 1)) {
                    int temp = list.get(in);
                    list.set(in, list.get(in + 1));
                    list.set(in + 1, temp);
                }
            }
        }
    }
}
